package com.ace.scenep.day0115;

/**
 * @author ：helongwei
 * @date ：Created in 2025/1/15 19:43
 * @description：
 * @modified By：
 * @version:
 */
public class MyCounterTest {
    public static void main(String[] args) {
        MyCounter counter = new MyCounter();

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "开始执行");
                for (int j = 1; j <= 10; j++) {
                    counter.increment();
                    System.out.println(Thread.currentThread().getName() + "执行了" + j + "次");
                }
            }).start();
        }

        // 等待所有线程执行完毕  获取结果
        while (Thread.activeCount() > 2) {
            Thread.yield();
        }
        System.out.println("计数结果：" + counter.getCount());


        //重置计数
        counter.reset();


        System.out.println("重置计数结果：" + counter.getCount());
    }
}